package maximumEnergyBoostFromTwoDrinks_3259;


//https://leetcode.cn/problems/maximum-energy-boost-from-two-drinks/
public class Solution {
    public long maxEnergyBoost(int[] energyDrinkA, int[] energyDrinkB) {
        long[][] dp = new long[energyDrinkA.length + 2][2];
        for (int i = 0; i < energyDrinkA.length; i++) {
            for (int j = 0; j < dp[i].length; j++) {
                int self;
                if (j == 0) {
                    self = energyDrinkA[i];
                } else {
                    self = energyDrinkB[i];
                }
                dp[i + 2][j] = Math.max(dp[i + 1][j], dp[i
                        ][j ^ 1]) + self;
            }
        }
        return Math.max(dp[energyDrinkA.length + 1][0], dp[energyDrinkA.length + 1][1]);
    }
}


//[1,3,1 ...]
//[3,1,1 ...]